Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat #297 Support default values from rich contract data #349

Merged

Conversation

rulfo71
Copy link
Contributor

@rulfo71 rulfo71 commented Sep 26, 2022

Description

Support default values from rich contract data. Disable input by default when receiving data. Adding unlock icon to enable.

22-09-26.Support.default.values.from.rich.contract.data.webm

2022-09-26 09-38-25 Support default values from rich contract data

Closes #297

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Tested manually and added Tests

Checklist:

  • My code follows the existing style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any UI changes have been tested and made responsive for mobile views

@github-actions
Copy link

✔️ Preview deployment is ready!

🔨 Explore the source changes: 5245054

😎 Browse the preview: https://bafybeiazxxbgkz6kern2suj5zoiqzoa6wp72pyswxwbz2yazevtvujxgze.ipfs.cf-ipfs.com

@github-actions
Copy link

✔️ Storybook deployment is ready!

😎 Browse Storybook: https://bafybeihifkqp7hm3cka773yp6ex6onwe4kxec6jfwig6mnhwxabzqlols4.ipfs.cf-ipfs.com

@github-actions
Copy link

✔️ Preview deployment is ready!

🔨 Explore the source changes: 3c6df13

😎 Browse the preview: https://bafybeigjndwkcqsosp6ksnzh2x2t67gtgwtlysbeczw5s2rifdvdbzu4ha.ipfs.cf-ipfs.com

@github-actions
Copy link

✔️ Storybook deployment is ready!

😎 Browse Storybook: https://bafybeie4hrunndder2q7y47lb2ykj4nhinxu3qxxmbodwod4bakcctydva.ipfs.cf-ipfs.com

@github-actions
Copy link

✔️ Preview deployment is ready!

🔨 Explore the source changes: 0308aef

😎 Browse the preview: https://bafybeigjndwkcqsosp6ksnzh2x2t67gtgwtlysbeczw5s2rifdvdbzu4ha.ipfs.cf-ipfs.com

@github-actions
Copy link

✔️ Storybook deployment is ready!

😎 Browse Storybook: https://bafybeigtv45hup6fegfqpz637y6vp5mcqiegsjqhs3gpmjmycjge2kuebm.ipfs.cf-ipfs.com

@dcrescimbeni
Copy link
Contributor

dcrescimbeni commented Sep 27, 2022

Here's a video of the interactions.

This causes this side-effects in:

  1. When we have a value in NumericalInput, it blocks its edit by default. Its OK in the context of editing default data from a contract, but unintended in other places we use that input, like a transfer call, or lock tokens.
  2. A similar behaviour is shown while editing a SetPermission call: the address is locked and the user has to click the icon to unlock it and edit it.

If I understand the issue correctly, the locking logic (preventing a user to mistakenly modify a default value in a contract call) should be only applied while making a contract call, not in other places we use the same component.

What's tricky about this is that currently I think we don't seem to have a mechanism to tell the component that it is inside a contract call, and that's the main challenge.

https://www.loom.com/share/96abee75c4674e62b812e80f55c540ab

image

@rulfo71 rulfo71 changed the title Default values from rich contract data Feat #349 Default values from rich contract data Sep 28, 2022
@rulfo71 rulfo71 changed the title Feat #349 Default values from rich contract data Feat #297 Default values from rich contract data Sep 28, 2022

const inputRegex = RegExp(`^\\d*(?:\\\\[.])?\\d*$`); // match escaped "." characters via in a non-capturing group

export const NumericalInput: React.FC<InputProps<string>> = ({
value,
onChange,
placeholder,
disabled = true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the default behaviour for all NumericalInputs to be locked (disabled).

The default should be disabled = false since in most cases its expected the user inputs a value.

This might be an unexpected side-effect of the fact that all values are initialized as BigNumber.from(0) t prevent errors.

Also it conflicts with the SetPermissions behaviour since a user can now unlock the amount field (originally locked and toggled to max).

Comment on lines 1 to 32
import { FiUnlock, FiX } from 'react-icons/fi';
import { ClickableIcon } from './AddressInput';

export const IconRight = ({
disabled = true,
value,
onChange,
setDisabled,
type,
}) => {
const clearLabel = `clear ${type}`;

if (!disabled && value) {
return (
<ClickableIcon aria-label={clearLabel} onClick={() => onChange('')}>
<FiX size={18} />
</ClickableIcon>
);
} else if (disabled) {
return (
<ClickableIcon
aria-label="enable"
onClick={() => {
setDisabled(false);
console.log(disabled);
}}
>
<FiUnlock size={18} />
</ClickableIcon>
);
} else return null;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we toggle the unlock button, we can't toggle it back on.

We have two competing icons: a lock and a clear (X) icon. Maybe if we show both the UI gets too crowded.

Just pointing this behaviour, I don't know what the end result should look like.

Copy link
Contributor Author

@rulfo71 rulfo71 Sep 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, yes, this is true. i don't think the idea was to lock the input after unlocking it but it's good you point it out

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can leave the behaviour as is right now and later consider how we would have a lock icon

Comment on lines 25 to 32
const [disabledState, setDisabled] = useState(value ? disabled : false);
const iconRightProps = {
disabled: disabledState,
value: value,
onChange: onChange,
setDisabled,
type: 'address',
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This locks the address field if it has value, like in the case of a user editing a function call permission.

@rulfo71 rulfo71 changed the title Feat #297 Default values from rich contract data Feat #297 Support default values from rich contract data Sep 29, 2022

const inputRegex = RegExp(`^\\d*(?:\\\\[.])?\\d*$`); // match escaped "." characters via in a non-capturing group

export const NumericalInput: React.FC<InputProps<string>> = ({
value,
onChange,
placeholder,
disabled = true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think passing defaultValue here would be more flexible in future and would limit the locking to when it is explicitly needed

@rossneilson
Copy link
Contributor

We found a bug where action index 2 on the contract for voting in dxvote is showing index 1 option when clicked. We have not had this behaviour before so would be great to fix here if it is simple.

@github-actions
Copy link

github-actions bot commented Oct 3, 2022

✔️ Storybook deployment is ready!

😎 Browse Storybook: https://bafybeidwarailizpqwpc2opbjcnkn4v6eipaxzspirvgcjplfejk7cfmpa.ipfs.cf-ipfs.com

@rulfo71
Copy link
Contributor Author

rulfo71 commented Oct 3, 2022

the branch is now mergeable, works locking the numerical or address input if it has a default value as requested.

Still missing:

  • tests
  • fix bug found where action index 2 on the contract for voting in dxvote is showing index 1 option when clicked

@dcrescimbeni
Copy link
Contributor

dcrescimbeni commented Oct 4, 2022

Nice! I've tested it and left some minor comments.

I think it works as intended now 👍

Also, it'll have conflicts with PR #369 , since we're both changing AddressInput, but shouldn't be anything significant.

About the pending tests: we should at least them to test the functionality of disabling the input if it has a default value and the unlock feature.

@rulfo71
Copy link
Contributor Author

rulfo71 commented Oct 23, 2022

"fix bug found where action index 2 on the contract for voting in dxvote is showing index 1 option when clicked"

this bug was caused because both functions had the same functionName "vote". I changed them to voteFor and voteAgainst and now it looks like this:
image

i'm not sure if it's the best ux for a non-technical user to see the function name and parameters but that's how it's done in other cases.

@dcrescimbeni
Copy link
Contributor

I'm having the same issue as Filip.

Created a transfer proposal, then created a voting proposal with the transfer proposal data (proposal ID and guild address), and I'm having an infinite loop on the action and can't see it in the proposal page.

@rulfo71
Copy link
Contributor Author

rulfo71 commented Nov 9, 2022

hey @Filipv95 can you try it out now please?
it's working for me, here you have a video.

  1. I created a proposal with just a transfer
  2. i got the proposal id from the url
  3. video, creating a proposal, adding the proposal id from 2)
    Screencast from 09-11-22 16:31:25.webm
    on the video you can see how i created the proposal. I ended it because my computer was being very slow but here you can see the proposal created:
    image

please try editing it as well because i'm having a problem but i think it's just my computer resources

@github-actions
Copy link

✔️ Storybook deployment is ready!

😎 Browse Storybook: https://bafybeigyaealukmvhb2xp5mqo3cjw3emziququigkbe3o2dpxigkhdvffu.ipfs.cf-ipfs.com

@github-actions
Copy link

✔️ Storybook deployment is ready!

😎 Browse Storybook: https://bafybeid4fyfbbacqy3jicpgt34uldvbyxqls5xsuxcp2nch746hyblleuq.ipfs.cf-ipfs.com

@dcrescimbeni
Copy link
Contributor

I can make a transfer proposal and a voting proposal for it 👍

LGTM

@0xvangrim
Copy link
Contributor

Hey Tomas! Sorry for not looking at this PR earlier. Have some comments on this issue:

  • Seems like we're missing some validation when the data length of the proposal ID is missing, for example. Should this be included in this PR or another issue? In my use case, I tried to add a wallet address instead of a proposal ID.

image

  • Some UI fixes needed for this (proposal ID is colliding with the buttons):

image

  • Personally, I think this looks a bit weird. As a user, I'd probably rather see "Vote YES with 1 REP". And then the vote decision should show YES or NO. But maybe it's a design decision that has been discussed already in which I rest my case.

image

Copy link
Contributor

@0xvangrim 0xvangrim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good ✅

@@ -6,3 +6,8 @@ export interface ActionModalProps {
onAddAction: (action: DecodedAction) => void;
action?: DecodedAction;
}

export interface SelectedFunction {
functionName: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep it consistent. Should this be either functionName and functionTitle or name and title?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this came from the richContracts but i agree with you, i'll change it :
image

@github-actions
Copy link

✔️ Storybook deployment is ready!

😎 Browse Storybook: https://bafybeiafimrb6p2ethd6y332tl4tmvc5cf4zrev5bx5jn2wzrrxfyrlf4u.ipfs.cf-ipfs.com

@rulfo71
Copy link
Contributor Author

rulfo71 commented Nov 18, 2022

Hey Tomas! Sorry for not looking at this PR earlier. Have some comments on this issue:

  • Seems like we're missing some validation when the data length of the proposal ID is missing, for example. Should this be included in this PR or another issue? In my use case, I tried to add a wallet address instead of a proposal ID.
image
  • Some UI fixes needed for this (proposal ID is colliding with the buttons):
image
  • Personally, I think this looks a bit weird. As a user, I'd probably rather see "Vote YES with 1 REP". And then the vote decision should show YES or NO. But maybe it's a design decision that has been discussed already in which I rest my case.
image

i'm validating now it is a bytes32 but i'm not sure if the text is the best for UX. open to suggestions:

image

@github-actions
Copy link

✔️ Storybook deployment is ready!

😎 Browse Storybook: https://bafybeihpumckuuc224j4gb3iklllk4cohmxlwfklhxdsl2kvcyrcc5jb5m.ipfs.cf-ipfs.com

@dcrescimbeni
Copy link
Contributor

Changes look good 👍

const BYTES_32_LENGTH = 66;

export function isBytes32(value: string) {
return value && value.length === BYTES_32_LENGTH;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could check also if it starts with 0x

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i thought about this but i'm not sure if it would be correct because of examples like this one i saw on richContracts:

image

this ones are component text so it isn't exactly the same but i thought it could happen.

just to be clear, if there is a possibility of having on richContracts a component "string" and type "bytes32" that it doesn't start with 0x we shouldn't add this condition.

Let me know what to think, no problem on adding it!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are using the text input here because bytes 32 accepts numbers and text, so the bytes32 is just verification on the text. So we don't change anything about how we pass the data, just if we accept it. So since all bytes will have 0x at the start we can have 0x check as well as length (coming from the 32 number)
But we can merge this now and add it later

Copy link
Contributor

@rossneilson rossneilson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing work Tomas!

@rulfo71 rulfo71 merged commit c6500be into DXgovernance:develop Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support default values from rich contract data
5 participants